import Common from '../../common/common.js';
let common = new Common;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //优惠券ID
    couponId: '',
    //优惠券
    coupon: {},
    //商品列表
    list: [],
    //是否有数据
    hasData: true,
  },

  /**
   *  获取优惠券详情
   */
  getCoupon: function () {
    var that = this;
    var data = {
      "couponId": that.data.couponId,
      orgSeq: that.data.orgSeq
    };
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    common.requestAjax('/api/promotion-service/v1/coupon/queryGoodsByCoupon', 'POST', data).then(res => {
      wx.hideLoading();
      if (res.data.code == 1) {
        var coupon = res.data.result;
        var list = coupon.memberGoodsInfoDTOS;
        this.setData({
          coupon: coupon,
          list: list
        })
        if (list == null || list.length == 0) {
          that.setData({
            hasData: false
          })
        }
      } else {
        common.showToast(res.data.message);
      }
    }).catch(err => {
      common.showToast(err);
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let couponId = options.couponId;

    this.setData({
      couponId: couponId,
      orgSeq: getApp().globalData.orgSeq
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //获取数据
    this.getCoupon();
  },
})